
/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

import java.util.Scanner;

class supermarketmanager {
    public static void main(String[]args){
        boolean flag = true;
        double Temp = 0;
        while (flag){

            priceTable();

            System.out.println("请输入您要购买的物品编号：(1~5)");
            Temp = price()+ Temp;
            System.out.println("您花费了￥" + Temp);
            System.out.println("（输入Y继续，N退出）");

            Scanner scanner= new Scanner(System.in);
            String judge= scanner.next();

            if (judge.equals("N")){     //循环模块
                System.out.println("您已经退出购物，请支付：￥"+Temp);
                System.out.println("谢谢您的惠顾！");
                flag = false;
            }else if (judge.equals("Y")) {
                System.out.println("购物系统继续");
            }else{
                System.out.println("Error 01 !!!");
                return;
            }
        }
    }

    public static void priceTable(){        //价目表
        System.out.println("\t\t\t商品价格表");
        System.out.println("——————————————————————————————————————————————");
        System.out.println("编号\t名称\t\t价格");
        System.out.println("1\t\t牙刷\t\t￥8.8");
        System.out.println("2\t\t毛巾\t\t￥10.0");
        System.out.println("3\t\t水杯\t\t￥18.8");
        System.out.println("4\t\t苹果\t\t￥12.5");
        System.out.println("5\t\t香蕉\t\t￥15.5");
    }

    public static double price(){      //输入编号获取商品价格
        double[] price = {0,8.8,10.0,18.8,12.5,15.5};       //将编号与价格关联

        Scanner scanner= new Scanner(System.in);
        int num= scanner.nextInt();
        return price[num];
    }
}

